import pygame
import sys
import time
import random
from pygame.locals import *
from bar import Bar
from pygame.sprite import Sprite, Group
from cube import Cube
from ball import Ball
from arkanoid_reader import Reader
from arkanoid_errors import UserDisq
from arkanoid_game import Game
from sound import Sound



screen_dimension = ( 800, 400 )
#pygame.mixer.pre_init(44100,16, 2, 4096)
pygame.init()
Sound("background_music").play_music()
pygame.display.set_caption('arkanoid')
#screen = pygame.display.set_mode( (800,400), pygame.FULLSCREEN )
screen = pygame.display.set_mode( screen_dimension )
pygame.mouse.set_visible(False)
stage = 1
game = Game(stage,screen)     

while True:
    try:
        if game.stage_end():
            stage = stage + 1
            game = Game( stage, screen )
        if game.is_end():
            print("end_game")
            game.end_game()
            for event in pygame.event.get():
                if event.type == KEYDOWN:
                    if event.key == K_ESCAPE:
                        sys.exit()
                    stage=1
                    game = Game(stage,screen)
            time.sleep(0.06)
        else:
            game.draw_game()
            time.sleep(0.02)
        
    except UserDisq as e:
        Sound('end_game').play()
        game.user_disq()